home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / asyam.zip / SETUART.C < prev    next >
C/C++ Source or Header  |  1993-06-24  |  2KB  |  102 lines

  1. #include <dos.h>
  2.  
  3. #include "async.h"
  4.  
  5. extern  int UART_ports[];
  6. extern  int UART_interrupts[];
  7. extern  int UART_onmask[];
  8. extern  int UART_offmask[];
  9.  
  10. extern  struct async_portS async_port[4];
  11.  
  12. void    set_UART_port(int comport, int value)
  13. {
  14.     UART_ports[comport] = value;
  15. }
  16.  
  17. void    set_UART_int(int comport, int value)
  18. {
  19.     UART_interrupts[comport] = value;
  20. }
  21.  
  22. void    set_UART_onmask(int comport, int value)
  23. {
  24.     UART_onmask[comport] = value;
  25. }
  26.  
  27. void    set_UART_offmask(int comport, int value)
  28. {
  29.     UART_offmask[comport] = value;
  30. }
  31.  
  32. int     set_parity(int comport, int parity)
  33. {
  34.     int     lcr;
  35.  
  36.     if (!async_port[comport].port_open) {
  37.         return (0);
  38.     }
  39.  
  40.     lcr = inportb(UART_ports[comport]+LCR);
  41.     lcr &= 199;
  42.     lcr |= parity;
  43.     outportb(UART_ports[comport]+LCR, lcr);
  44.  
  45.     return (1);
  46. }
  47.  
  48. int     set_stopbits(int comport, int stopbits)
  49. {
  50.     int     lcr;
  51.  
  52.     if (!async_port[comport].port_open) {
  53.         return (0);
  54.     }
  55.  
  56.     lcr = inportb(UART_ports[comport]+LCR);
  57.     lcr &= 251;
  58.     lcr |= (stopbits-1)*4;
  59.     outportb(UART_ports[comport]+LCR, lcr);
  60.  
  61.     return (1);
  62. }
  63.  
  64. int     set_wordlength(int comport, int wordlength)
  65. {
  66.     int     lcr;
  67.  
  68.     if (!async_port[comport].port_open) {
  69.         return (0);
  70.     }
  71.  
  72.     lcr = inportb(UART_ports[comport]+LCR);
  73.     lcr &= 252;
  74.     lcr |= (wordlength-5);
  75.     outportb(UART_ports[comport]+LCR, lcr);
  76.  
  77.     return (1);
  78. }
  79.  
  80. int     set_baudrate(int comport, long baudrate)
  81. {
  82.     int     divisor, lcr;
  83.  
  84.     if (!async_port[comport].port_open) {
  85.         return (0);
  86.     }
  87.  
  88.     // Set UART Baud Rate
  89.     lcr = inportb(UART_ports[comport]+LCR);
  90.     divisor = (115200L/baudrate);
  91.     outportb(UART_ports[comport]+LCR, 0x80);
  92.     outport(UART_ports[comport], divisor);
  93.     outportb(UART_ports[comport]+LCR, lcr);
  94.  
  95.     return (1);
  96. }
  97.  
  98. void    set_handshaking(int comport, int status)
  99. {
  100.     async_port[comport].handshaking = status;
  101. }
  102.